<?php

namespace App\Admin\Controllers;

use App\Models\CtsProduct;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;

class CtsProductController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header('旅行社产品');
            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(CtsProduct::class, function (Grid $grid) {
            $grid->actions(function ($actions) {
                $actions->disableView();
            });
            $grid->disableExport();
            $grid->disableFilter();
            $grid->id('ID')->sortable();
            $grid->cts('旅行社');
            $grid->title('名称');
            $grid->sale('月销量');
            $grid->ota('销售渠道');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(CtsProduct::class, function (Form $form) {
            $form->display('id', 'ID');//
            $form->text('cts','旅行社');
            $form->text('title', '名称');
            $form->number('sale','月销量');
            $form->rate('like_rate','好评率');
            $form->tags('ota','ota销售渠道');
            $form->text('leave_location','出发地');
            $form->radio('type','状态')->options(config('options.cts_product_type'));
        });
    }
}
